#include    "field-generator.h"

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
FieldGenerator::FieldGenerator(QObject *parent) : Device(parent)
  , omega(0.0)
  , In(0.0)
  , Ra(0.0747)
  , Rf(8.0)
  , Uf(0.0)
  , U(0.0)
  , M(0.0)
  , Kf(0.07)
  , Tf(0.1)
{

}

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
FieldGenerator::~FieldGenerator()
{

}

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void FieldGenerator::preStep(state_vector_t &Y, double t)
{
    Q_UNUSED(t)

    U = Kf * Y[0] * omega - Ra * In;

    M = Kf * Y[0] * In * sign(omega);
}

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void FieldGenerator::ode_system(const state_vector_t &Y,
                                state_vector_t &dYdt,
                                double t)
{
    Q_UNUSED(t)

    dYdt[0] = (Uf - Rf * Y[0]) / Tf / Rf;
}

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void FieldGenerator::load_config(CfgReader &cfg)
{
    Q_UNUSED(cfg)
}